package com.ssm.platform.controller;

import com.ssm.platform.pojo.vo.MenusVo;
import com.ssm.platform.service.IMenusService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "菜单")
@RestController
@RequestMapping("menus")
@RequiredArgsConstructor
public class MenusController {
    final IMenusService menusService;

    @GetMapping("list")
    @Operation(summary = "根据用户名获取菜单(列表)")
    public List<MenusVo> list(@Parameter(hidden = true) @AuthenticationPrincipal User user) {
        return menusService.list(user.getUsername());
    }

    @GetMapping("tree")
    @Operation(summary = "根据用户名获取菜单(树)")
    public List<MenusVo> tree(@Parameter(hidden = true) @AuthenticationPrincipal User user) {
        return menusService.tree(user.getUsername());
    }
}
